const App = {
  mixins: [Save],
  data() {
    return {
      category: [],
      dataForm: {
        Organization_name: '',
        description: '',
        CreateDate: '',
        Parent_SerialNumber: ''
      }
    };
  },
  mounted() {

    this.fetchCategory();
    // if (this.action === 'Modify' && this.nodeKey) {
    //   this.getData(this.nodeKey);
    // }
  },
  methods: {
    // 重写 handleSubmit 方法以确保数据正确提交
    async handleSubmit() {
      const allValid = await this.validateAllForms();
      if (allValid) {
        this.loading = true;
        
        // 确保数据格式正确
        const submitData = {
          ...this.dataForm,
          // 如果有日期格式转换需求可以在这里处理
          CreateDate: this.dataForm.CreateDate || null
        };
        
        // 调用父级保存逻辑
        this.$options.mixins[0].methods.handleSubmit.call(this);
      } else {
        this.$message({
          message: '请填写所有必填项！',
          type: 'warning'
        });
      }
    },
        fetchCategory() {
      const _this = this;
      $.ajax({
        headers: requestHeaders(),
        url: `${mh}/generalBusiness/generalQueryForObtainingTrees`,
        type: "GET",
        data: { TableName: "north_organization" },
        success: (data) => {
          _this.category = _this.convertToCascaderFormat(data);
        },
        error: (xhr) => console.error("分类树加载失败", xhr)
      });
    },
        convertToCascaderFormat(items) {
      const _this = this;
      console.log(items);
      return items.map((item) => ({
        label: item.Organization_name,
        value: item.Organization_SerialNumber,
        // 递归处理子节点
        children: item.children
          ? _this.convertToCascaderFormat(item.children)
          : [],
      }));
    },
  }
};

const { createApp } = Vue;
const app = createApp(App);
app.use(ElementPlus, { locale: zhCn });

// 注册图标组件
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  app.component(key, component);
}

app.mount("#app");